﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Windows;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace WpfApplication1
{
    public class InternetConnection : INotifyPropertyChanged
    {

       [DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(out int description, int reservedValue);
        public bool IsConnectedToInternet()
        {
            int desc;
            return InternetGetConnectedState(out desc, 0);
        }

        public bool IsConnect;
        public string isVisible_Connected;
        public string IsVisible_Connected
        {
            get
            {
                if (IsConnect == true)
                {
                    return "Visible";
                }
                else
                {
                    return "";
                }
            }
            set
            {
                isVisible_Connected=value;
                OnPropertyChanged("IsVisible_Connected");
            }
        }
        public string isVisible_DisConnected;
        public string IsVisible_DisConnected
        {
            get
            {
                if (IsConnect == false)
                {
                    return "Visible";
                }
                else
                {
                    return "";
                }
            }
            set
            {
                isVisible_DisConnected = value;
                OnPropertyChanged("IsVisible_DisConnected");
            }
        }
        public string status;
        public string Status
        {
            get
            {
                if (IsConnect == true)
                {
                    return "Connected";
                }
                else
                {
                    return "Disconnected";
                }
            }
            set
            {
                status = value;
                OnPropertyChanged("Status");
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged(string propertyName)
        {
            var handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }
       
        public InternetConnection()
        {
            IsConnect = IsConnectedToInternet();
        }
        
    }
}
